<?php
/**
 * GroupAccountController is used for business group account login and list merchant accounts.
 * 
 * LBB Solutions Oy 版权所有 © 2013
 */
class GroupAccountController extends Controller
{
	/**
	 * @return array action filters
	 */
	public function filters() {
		return array(
			'accessControl', // perform access control for CRUD operations
		);
	}

	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules() {
		return array(
			array('allow', // allow all users to perform below actions
				'actions'=>array('login'),
				'users'=>array('*'),
			),
			array('allow', // allow authenticated user to perform below actions
				'actions'=>array('logout', 'index'),
				'users'=>array('@'),
			),
			array('deny',  // deny all users
				'actions'=>array('logout', 'index'),
				'users'=>array('*'),
			),
		);
	}
	
	public function actionIndex()
	{
		$this->render('index');
	}
	
	public function actionLogin()
	{
		$this->layout = '//layouts/layout-accounts';
		$model = new LoginForm('login');

		BUtils::LoggingAction(Yii::app()->user->id, 0);
		// display the login form
		$this->render('login', array('model'=>$model));
	}

	public function actionLogout()
	{
		BUtils::LoggingAction(Yii::app()->user->id, 1);
		Yii::app()->user->logout();
		$this->redirect(Yii::app()->homeUrl);
	}
}